package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ServiceAddress;
import com.ruoyi.system.service.IServiceAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务地址
Controller
 * 
 * @author ruoyi
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/system/address")
public class ServiceAddressController extends BaseController
{
    @Autowired
    private IServiceAddressService serviceAddressService;

    /**
     * 查询服务地址
列表
     */
//    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceAddress serviceAddress)
    {
        startPage();
        List<ServiceAddress> list = serviceAddressService.selectServiceAddressList(serviceAddress);
        return getDataTable(list);
    }

    /**
     * 导出服务地址
列表
     */
//    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "服务地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ServiceAddress serviceAddress)
    {
        List<ServiceAddress> list = serviceAddressService.selectServiceAddressList(serviceAddress);
        ExcelUtil<ServiceAddress> util = new ExcelUtil<ServiceAddress>(ServiceAddress.class);
        return util.exportExcel(list, "address");
    }

    /**
     * 获取服务地址
详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{saId}")
    public AjaxResult getInfo(@PathVariable("saId") Long saId)
    {
        return AjaxResult.success(serviceAddressService.selectServiceAddressById(saId));
    }

    /**
     * 新增服务地址

     */
//    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "服务地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceAddress serviceAddress)
    {
        return toAjax(serviceAddressService.insertServiceAddress(serviceAddress));
    }

    /**
     * 修改服务地址

     */
//    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "服务地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceAddress serviceAddress)
    {
        return toAjax(serviceAddressService.updateServiceAddress(serviceAddress));
    }

    /**
     * 删除服务地址

     */
//    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "服务地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saIds}")
    public AjaxResult remove(@PathVariable Long[] saIds)
    {
        return toAjax(serviceAddressService.deleteServiceAddressByIds(saIds));
    }
}
